const WITHDRAW_STATUS = {
  'problems': '有问题',
  'suspicious': '可疑',
  'cancelled': '已取消',
  'scheduled': '等待操作',
  'rejected': '被拒绝',
  'pending': '等待中',
  'accepted': '等待操作',
  'retrieved': '已接收'
}
const WITHDRAW_STATUS_COLOR = {
  'problems': 'danger',
  'cancelled': 'info',
  'rejected': 'info',
  'pending': 'warning',
  'accepted': 'info',
  'retrieved': 'success',
  'suspicious': 'danger'
}

const PAYMENT = {
  'huifu': '汇付',
  'fuiou': '富友',
  'manual': '线下'
}

export default {
  Withdraw: {
    list: {
      // 额外component异步获取的数据如果需要导出，要独立界面和导出方法
      export: {
        query: {
          '@display': `{
          'id' : 'entity.getId()',
          'user' : 'entity.getUser().getUsername()',
          'batchNo' : 'entity.getBatchNo()',
          'amount' : 'entity.getAmount()',
          'fee',
          'status' : '{ "problems": "有问题", "cancelled": "已取消", "rejected": "被拒绝", "pending": "等待中", "accepted": "已通过", "retrieved": "已接收" }[entity.getStatus()]',
          'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")',
          'payment' : 'entity.getPayment()'
        }`,
          limit: 10000000
        },
        label: {
          'id': 'id',
          'user': '用户',
          'batchNo': '批号',
          'amount': '金额',
          'fee': '手续费',
          'status': '状态',
          'createdTime': '创建时间',
          'payment': '提现渠道'
        }
      },
      disabled_actions: ['new', 'delete'],
      query: {
        '@order': 'entity.id|DESC'
      },
      list_filter: {
        'user.username': '电话',
        status: Object.assign({ __label: '状态' }, WITHDRAW_STATUS),
        beforeCreatedTime: {
          expression: 'entity.getCreatedTime() >= datetime.get(":value  00:00:00")',
          label: '开始时间',
          type: 'date'
        },
        afterCreatedTime: {
          expression: 'entity.getCreatedTime() < datetime.get(":value 23:59:59")',
          label: '结束时间',
          type: 'date'
        },
        hadPay: {
          expression: 'entity.getFee() == :value',
          label: '快速提现',
          type: 'input'
        }
      },
      list_display: [
        'id',
        'user',
        {
          property: 'extraData',
          label: '提现账号',
          component: {
            props: ['data'],
            render(h) {
              return <div>
                <div>银行:{this.data.card.bankName}</div>
                <div>分行号:{this.data.card.branch}</div>
                <div>账号:{this.data.card.no}</div>
                <div>姓名:{this.data.card.name}</div>
              </div>
            }
          }
        },
        // {
        //   property: 'user',
        //   label: '汇付账号',
        //   component: {
        //     props: ['data'],
        //     data() {
        //       return {
        //         name: '无绑定'
        //       }
        //     },
        //     created() {
        //       this.axios.get(`/manage/huifu-accounts`, { params: { '@filter': `entity.getUser().getId() == ${this.data.id}` } }).then((res) => {
        //         if (res.data.length > 0) {
        //           this.name = '汇付:' + res.data[0].cardInfo.card_name + `(${res.data[0].store.__toString})`
        //         }
        //       })
        //     },
        //     render(h) {
        //       return <div style='width:220px'>{this.name}</div>
        //     }
        //   }
        // },
        'batchNo',
        'amount',
        // { property: 'fee', label: '手续费' },
        {
          property: 'status',
          component: {
            props: ['data'],
            data() {
              return {
                status: WITHDRAW_STATUS,
                color: WITHDRAW_STATUS_COLOR
              }
            },
            render(h) {
              return <el-tag type={this.color[this.data]} effect='plain'>{this.status[this.data]}</el-tag>
            }
          }
        },
        'createdTime',
        'lastModifiedTime',
        {
          property: 'payment',
          label: '提现渠道',
          component: {
            props: ['data'],
            render(h) {
              return <div>{PAYMENT[this.data]}</div>
            }
          }
        }
      ]
    },
    form: {
      fields: [
        {
          property: 'status',
          type: 'select',
          type_options: {
            options: [
              { value: 'scheduled', label: '等待处理' },
              { value: 'accepted', label: '等待汇款' },
              { value: 'retrieved', label: '已接收' }
            ]
          }
        },
      ]
    }
  }
}

